<?php
class Image_Bd{
	
	public static function getImageByIdUser($id) {  
	
		$db = Outils_Bd::getInstance()->getConnexion();
		$sth=$db->prepare("SELECT * FROM Image WHERE id_user=:id LIMIT 1");
		$data=array('id' => $id);
		$sth->execute($data);
		$ligne = $sth->fetch(PDO::FETCH_ASSOC);
		if (! $ligne)
			return false;
		return Image::initializeFromData($ligne);
}


  static public function saveImage($image) { 

   /* creer la connection BD */
    $db = Outils_Bd::getInstance()->getConnexion();
    /* preparer le requete */
    $sth=$db->prepare("insert into Image set id_user=:id_user, extension=:extension, mime=:mime,time=:time, id_image=:id_image");

    /* recuperer les donnes */
    $data=array(
		'id_user' => $image->getIdUser(),
		'extension' => $image->getExtension(),
		'mime' => $image->getMime(),
		'time' => $image->getTime(),
		'id_image'=> $image->getIdImage()
		);

    /* executer la requete */
    $sth->execute($data);
  }

 /* Méthode enregistrer() : enregistre les données dans la BdD */
  static public function deleteUserImage($id_user) { 

   /* creer la connection BD */
    $db = Outils_Bd::getInstance()->getConnexion();
    /* preparer le requete */
    $req=$db->prepare("delete from Image where id_user=:id");
    /* recuperer les donnes */
    $data=array('id' => $id_user);
    /* executer la requete */
    $req->execute($data);
  
	}	
	
	
}


?>